package com.ncloud.system.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ncloud.common.exception.UserException;
import com.ncloud.system.mapper.SequenceMapper;
import com.ncloud.system.service.SequenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SequenceServiceImpl implements SequenceService {
	
	@Autowired
	private SequenceMapper mapper;

	@Override
	public synchronized Long getSequence(JSONObject json) {
		if(!json.containsKey("seqName")){
			throw new UserException(2001, "传入参数有误");
		}
		String seqName = json.getString("seqName");
		Long seqVal = mapper.getSequence(seqName );
		return seqVal;
	}

	@Override
	public synchronized Long getSequence(String seqName) {
		return mapper.getSequence(seqName );
	}
}
